package com.cdwh.joylife.utils;

import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.widget.Toast;

import com.cdwh.joylife.App;


public class AppToast {

    protected static final String TAG = "AppToast";
    public static Toast toast;
    private static AlertDialog dialog;



//    public static void makeToast(Activity activity,String content) {
//        if (dialog != null) {
//            dialog.dismiss();
//        }
//        dialog = new AlertDialog.Builder(activity)
//                .setTitle("提示")
//                .setMessage(content)
//                .setPositiveButton("确定", null)
//                .show();
//    }
    /**
     * 信息提示
     *
     * @author huxing
     * create at 2016-04-12 9:45
     */
    public static void makeToast(String content) {
        if (toast != null)
            toast.cancel();
//		Socket closed
        if (TextUtils.isEmpty(content) || content.endsWith("Socket closed")) {
            return;
        }
        if (content.contains("connect") || content.contains("No address associated with hostname")) {
            content = "网络异常，请检查网络";
        }
        if (content.contains("500")) {
            content = "服务器异常，请稍后再试";
        }
        if (content.contains("404")) {
            content = "服务器异常，请稍后再试";
        }
//        if (content.contains(String.valueOf(Constants.TOKEN_OVERDUE))) {
//            EventBus.getDefault().post(new LoginOverdue());
//        }
        toast = Toast.makeText(App.getContext(), content, Toast.LENGTH_LONG);
        toast.show();
    }

    public static void showShortText(int resId) {
        try {

            if (toast != null)
                toast.cancel();
            toast = Toast.makeText(App.getContext(), App.getContext().getString(resId), Toast.LENGTH_SHORT);
            toast.show();
        } catch (Exception e) {
        }
    }

    public static void showShortText(CharSequence text) {

        if (toast != null)
            toast.cancel();
        toast = Toast.makeText(App.getContext(), text, Toast.LENGTH_SHORT);
        toast.show();
    }

    public static void showLongText(int resId) {
        try {
            if (toast != null)
                toast.cancel();
            toast = Toast.makeText(App.getContext(), App.getContext().getString(resId), Toast.LENGTH_LONG);
            toast.show();

        } catch (Exception e) {
        }
    }

    public static void showLongText(CharSequence text) {

        if (toast != null)
            toast.cancel();
        toast = Toast.makeText(App.getContext(), text, Toast.LENGTH_LONG);
        toast.show();
    }
}
